// generating config files for a physical node
// Created: Apr. 13, 2023 by SUN Yazhou, asia.rabbit@163.com

#ifndef PN_h
#define PN_h

#include <yaml-cpp/yaml.h>
#include <string>
#include <fstream>
#include <map>
#include "types.h"
#include "LN.h"

using std::ofstream;
using YAML::Node;
using std::map;
using std::string;

class PN{
public:
  PN(const Node &n, CRATE_TYPE type);
  virtual ~PN();

  ofstream &file(){ return ff; }

  virtual void Generate(); // do the job
  // if they are the same PN (compare IP)
  virtual bool operator==(const PN &p){ return fIP == p.fIP; }

  virtual void Head(); // generate the head of the file
  virtual void Ln() = 0; // configure all the lns
  int nl() const{ return fLnMap.size(); } // nof ln-s
  CRATE_TYPE CrateType() const{ return fType; }

  LN *AddLn(int id, LN *ln);
  // generate config files for various ln types //
  LN *data_save(int id);
  LN *sys_console_gui(int id);
  LN *reduce_index(int id, STREAM_TYPE type);
  LN *map_index(int id, STREAM_TYPE type);
  LN *receive(int id, STREAM_TYPE type);
  LN *transmit(int id, STREAM_TYPE type);
  LN *dsi(int id, const string opt);
  LN *master_trigger(int id, const string opt);
  LN *slave_trigger(int id, const string opt);

protected:
  Node fn;
  CRATE_TYPE fType;
  string fIP;
  ofstream ff;
  map<int, LN *> fLnMap;
};

#endif
